{{define "role/add.html"}}
<!DOCTYPE html>
<html>
	<head>
        {{template "header"}}
	</head>

	<body>
		<div class="weadmin-nav">
            <span class="layui-breadcrumb">
                <a href="/welcome">首页</a>
                <a href="/admin/role/list">角色管理</a>
                <a><cite>添加角色</cite></a>
            </span>
		</div>
		<div class="weadmin-body">
			<form class="layui-form">
				<div class="layui-form-item">
					<div class="layui-inline">
						<label for="L_rolename" class="layui-form-label">
							<span class="we-red">*</span>角色名称
						</label>
						<div class="layui-input-inline">
							<input type="text" id="L_rolename" name="rolename" lay-verify="rolename" autocomplete="off" class="layui-input" placeholder="角色名称">
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-inline">
						<label for="L_state" class="layui-form-label">状态</label>
						<div class="layui-input-block">
							<input type="checkbox" name="state" id="L_state" lay-skin="switch"
								lay-text="启用|禁用" value="1" checked>
						</div>
					</div>
				</div>
				<div class="layui-form-item">
					<button class="layui-btn fr" lay-filter="add" lay-submit="">确定</button>
				</div>
			</form>
		</div>
    </body>

    {{template "jsfile"}}
	<script type="text/javascript">
		layui.extend({
			admin: '/static/js/admin',
		});
		layui.use(['jquery', 'form','element', 'admin', 'carousel'], function() {
			var element = layui.element,
				$ = layui.jquery,
				carousel = layui.carousel,
				form = layui.form,
				admin = layui.admin;
			//建造实例
			carousel.render({
				elem: '.weadmin-shortcut'
				,width: '100%' //设置容器宽度
				,arrow: 'none' //始终显示箭头
				,trigger: 'hover'
				,autoplay:false
			});

			form.verify({
				rolename: function(value){
					if(value.length <= 0){
						return '角色名称不允许为空!';
					}
				}
			})

			//监听提交
			form.on('submit(add)', function(data){
				$.post("/admin/role/add",data.field,function(result){
					if(result.status){
						layer.msg("添加角色成功!",{time:3*1000,icon:1},function(){
							//自动关闭layer
							var index = parent.layer.getFrameIndex(window.name);
							parent.layer.close(index);
							//刷新list
							parent.roleRefreshForm();
						})
					}else{
						layer.msg(result.message,{time:6*1000,icon:2})
					}
				},"json");
				return false;
			});
		});
	</script>

</html>
{{end}}